   package com.news.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.news.entity.Page;
import com.news.entity.User;
import com.news.service.UserPageService;


@WebServlet("/adminuserlist")
public class AdminUserListServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取用户单击的页码
		String current= request.getParameter("current");
		UserPageService pageService=new UserPageService();	
		//第一次访问列表没有current参数，则默认显示第1页数据
		int curPage=(current==null?1: Integer.parseInt(current));
		//获取当前页码需要显示的品牌列表
		List<User> users=pageService.getUsersByCurrentPage(curPage);
		//获取所有页码列表
		List<Page> pages= pageService.getPages();
						
		//将数据放到request域中，通过请求转发传递到页面
		request.setAttribute("users", users);//品牌列表
		request.setAttribute("pages", pages);//页码列表
		request.setAttribute("curPage", curPage);//当前页码
		request.setAttribute("pageCount", pages.size());//总页码
		//跳转页面
		request.getRequestDispatcher("/jsp/adminuserlist.jsp").forward(request, response);
	}

}
